//
//  LSRollingBallCell.m
//  LookScore
//
//  Created by wr on 2018/3/20.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSRollingBallCell.h"
#import "EdgeInsetsLabel.h"
#import "LSRollModel.h"

#pragma mark --LSRollingBallCell
@interface LSRollingBallCell()

@property(strong,nonatomic)UIView *backView;
@property (nonatomic, strong) UILabel *hostProbabilityLab;
@property (nonatomic, strong) UILabel *midProbabilityLab;
@property (nonatomic, strong) UILabel *guestProbabilityLab;
@property (nonatomic, strong) UIImageView * leftImageView;
@property (nonatomic, strong) UIImageView * rightImageView;
@end

@implementation LSRollingBallCell

+(LSRollingBallCell *)RollingBallCellByTableView:(UITableView *)tableView{
    
    LSRollingBallCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSRollingBallCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    
    return self;
}

-(void)addContentView{
    
    UIView *backView=[[UIView alloc]init];
    [self.contentView addSubview:backView];
    
    UILabel *middelLabel = [[UILabel alloc] init];
    middelLabel.textAlignment = NSTextAlignmentCenter;
    middelLabel.font = LSFontSize12;
    middelLabel.textColor = LSTitleGrayColor2;
    middelLabel.text= @"VS";
    [self.contentView addSubview:middelLabel];
    middelLabel.sd_layout
    .centerXEqualToView(self.contentView)
    .topSpaceToView(self.contentView, 20)
    .autoHeightRatio(0);
    [middelLabel setSingleLineAutoResizeWithMaxWidth:180];
    _leftImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logoNull"]];
    [self.contentView addSubview:_leftImageView];
    _leftImageView.sd_layout
    .centerXIs(LSScreenWidth/3)
    .centerYEqualToView(middelLabel)
    .widthIs(26)
    .heightIs(26);
    
    
    _rightImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logoNull"]];
    [self.contentView addSubview:_rightImageView];
    _rightImageView.sd_layout
    .centerYEqualToView(middelLabel)
    .centerXIs(LSScreenWidth*2/3)
    .widthIs(26)
    .heightIs(26);
    
    
    _hostProbabilityLab = [[UILabel alloc] init];
    _hostProbabilityLab.font = LSFontSize12;
    _hostProbabilityLab.backgroundColor = RGB(241,43,43);
    _hostProbabilityLab.textAlignment = NSTextAlignmentCenter;
    _hostProbabilityLab.text = @"主胜33.3%";
    _hostProbabilityLab.textColor = LSTitleWhiteColor;
    [self.contentView addSubview:_hostProbabilityLab];
    _hostProbabilityLab.sd_layout
    .leftSpaceToView(self.contentView, 10)
    .topSpaceToView(_leftImageView, 10)
    .heightIs(35)
    .widthIs((LSScreenWidth-20)/3);
    
    
    _midProbabilityLab = [[UILabel alloc] init];
    _midProbabilityLab.font = LSFontSize12;
    _midProbabilityLab.text = @"平33.3%";
    _midProbabilityLab.textColor = LSTitleWhiteColor;
    _midProbabilityLab.backgroundColor = RGB(73,200,103);
    _midProbabilityLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_midProbabilityLab];
    _midProbabilityLab.sd_layout
    .leftSpaceToView(_hostProbabilityLab, 0)
    .centerYEqualToView(_hostProbabilityLab)
    .heightIs(35)
    .widthIs((LSScreenWidth-20)/3);
    
    _guestProbabilityLab = [[UILabel alloc] init];
    _guestProbabilityLab.font = LSFontSize12;
    _guestProbabilityLab.textColor = LSTitleWhiteColor;
    _guestProbabilityLab.text = @"客胜33.3%";
    _guestProbabilityLab.backgroundColor = RGB(22,125,204);
    _guestProbabilityLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_guestProbabilityLab];
    _guestProbabilityLab.sd_layout
    .leftSpaceToView(_midProbabilityLab, 0)
    .topSpaceToView(_rightImageView, 10)
    .heightIs(35)
    .widthIs((LSScreenWidth-20)/3);
    
}
- (void)setHomeId:(NSInteger)homeId{
    _homeId = homeId;
    [_leftImageView sd_setImageWithURL:[NSURL URLWithString:TeamImageHeaderUrl(homeId)] placeholderImage:[UIImage imageNamed:@"logoNull"]];
}

   

- (void)setGuestId:(NSInteger)guestId{
    _guestId = guestId;
    [_rightImageView sd_setImageWithURL:[NSURL URLWithString:TeamImageHeaderUrl(guestId)] placeholderImage:[UIImage imageNamed:@"logoNull"]];
}

- (void)setModel:(LSRollModel *)model{
    _model = model;
//    MyLog(@"%f",model.WinPercentage.floatValue);
    
    if ([CommonClass isBlankString:model.WinPercentage] && [CommonClass isBlankString:model.LosePercentage] && [CommonClass isBlankString:model.FlatPercentage]){
        
        _hostProbabilityLab.text = @"主";
        _guestProbabilityLab.text = @"客";
        _midProbabilityLab.text = @"平";
    }else{
        _hostProbabilityLab.text = [NSString stringWithFormat:@"主胜%@",model.WinPercentage];
        _hostProbabilityLab.sd_layout
        .widthIs(model.WinPercentage.floatValue/100 * (LSScreenWidth - 20));
        _guestProbabilityLab.text = [NSString stringWithFormat:@"客胜%@",model.LosePercentage];
        _guestProbabilityLab.sd_layout
        .widthIs(model.LosePercentage.floatValue/100*(LSScreenWidth -20));
        _midProbabilityLab.text = [NSString stringWithFormat:@"平%@",model.FlatPercentage];
        _midProbabilityLab.sd_layout
        .widthIs(model.FlatPercentage.floatValue/100 * (LSScreenWidth - 20));
    }
    
    
}

@end

@interface LSExpertAnalysisCell()

@property (nonatomic, strong) UIImageView * iconImageView;
@property (nonatomic, strong) UILabel * nickNameLab;
@property (nonatomic, strong) UILabel * shootingLab;
@property (nonatomic, strong) EdgeInsetsLabel * leftShootingLab;
@property (nonatomic, strong) EdgeInsetsLabel * shootingNumbLabel;

@property (nonatomic, strong) UILabel * contentLabel;
@property (nonatomic, strong) UIButton * lookBtn;
@property (nonatomic, strong) UILabel * timeLabel;
@property (nonatomic, strong) UIButton * attentBtn;
@property (nonatomic, strong) UIImageView * mosaicImageView;
@end

@implementation LSExpertAnalysisCell

+ (LSExpertAnalysisCell *)LSExpertAnalysisCellByTableView:(UITableView *)tableView{
    
    LSExpertAnalysisCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    if (!cell) {
        cell = [[LSExpertAnalysisCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        
    }
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContenView];
    }
    
    return self;
}

- (void)addContenView{
    _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo1"]];
    [self.contentView addSubview:_iconImageView];
    _iconImageView.sd_layout
    .leftSpaceToView(self.contentView, 10)
    .topSpaceToView(self.contentView, 5);
    
    _nickNameLab = [[UILabel alloc] init];
    _nickNameLab.font = LSFontSize13;
    _nickNameLab.text = @"精华水月";
    _nickNameLab.textColor = LSTitleGrayColor1;
    [self.contentView addSubview:_nickNameLab];
    _nickNameLab.sd_layout
    .leftSpaceToView(_iconImageView, 5)
    .topSpaceToView(self.contentView, 8)
    .autoHeightRatio(0);
    [_nickNameLab setSingleLineAutoResizeWithMaxWidth:180];
    
    _leftShootingLab = [[EdgeInsetsLabel alloc] init];
    _leftShootingLab.text = @"100%命中率";
    _leftShootingLab.textAlignment = NSTextAlignmentCenter;
    _leftShootingLab.textColor = RGB(255,126,0);
    _leftShootingLab.font = LSFontSize10;
    _leftShootingLab.layer.borderColor = RGB(255,126,0).CGColor;
    _leftShootingLab.layer.cornerRadius = 4;
    _leftShootingLab.layer.borderWidth = 0.5;
   
    [self.contentView addSubview:_leftShootingLab];
    _leftShootingLab.sd_layout
    .leftEqualToView(_nickNameLab)
    .topSpaceToView(_nickNameLab, 3)
    .widthIs(60)
    .heightIs(15);
//    [_leftShootingLab setSingleLineAutoResizeWithMaxWidth:180];
     _leftShootingLab.contentInset = UIEdgeInsetsMake(3, 3, 3, 3);
    _shootingNumbLabel = [[EdgeInsetsLabel alloc] init];
    _shootingNumbLabel.text = @"近13中12";
    _shootingNumbLabel.textAlignment = NSTextAlignmentCenter;
    _shootingNumbLabel.textColor = RGB(255,126,0);
    _shootingNumbLabel.font = LSFontSize10;
    _shootingNumbLabel.layer.borderWidth = 0.5;
    _shootingNumbLabel.layer.borderColor = RGB(255,126,0).CGColor;
    _shootingNumbLabel.cornerRadius = 4;
    _shootingNumbLabel.contentInset = UIEdgeInsetsMake(3, 3, 3, 3);
    [self.contentView addSubview:_shootingNumbLabel];
    _shootingNumbLabel.sd_layout
    .leftSpaceToView(_leftShootingLab, 3)
    .centerYEqualToView(_leftShootingLab)
    .widthIs(50)
    .heightIs(15);
//    [_shootingNumbLabel setSingleLineAutoResizeWithMaxWidth:180];
     _shootingNumbLabel.contentInset = UIEdgeInsetsMake(3, 3, 3, 3);
    
    _shootingLab = [[UILabel alloc] init];
    _shootingLab.font = LSFontSize12;
    _shootingLab.text = @"100%\n命中率";
    _shootingLab.textAlignment = NSTextAlignmentCenter;
    _shootingLab.textColor = [UIColor redColor];
    [self.contentView addSubview:_shootingLab];
    _shootingLab.sd_layout
    .rightSpaceToView(self.contentView, 10)
    .topSpaceToView(self.contentView, 8)
    .autoHeightRatio(0);
    [_shootingLab setSingleLineAutoResizeWithMaxWidth:180];
    

    _contentLabel = [[UILabel alloc] init];
    _contentLabel.font = LSFontSize12;
    _contentLabel.text = @"罗马主场能否再次上演奇迹";
    _contentLabel.numberOfLines = 0;
    _contentLabel.textColor = LSTitleGrayColor1;
    [self.contentView addSubview:_contentLabel];
    _contentLabel.sd_layout
    .leftEqualToView(_iconImageView)
    .rightEqualToView(_shootingLab)
    .topSpaceToView(_iconImageView, 10)
    .autoHeightRatio(0);
    
    _lookBtn = [[UIButton alloc] init];
    [_lookBtn setTitle:@"查看" forState:UIControlStateNormal];
    [_lookBtn setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    _lookBtn.titleLabel.font = LSFontSize10;
    [_lookBtn addTarget:self action:@selector(lookBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_lookBtn];
    _lookBtn.sd_layout
    .leftEqualToView(_contentLabel)
    .topSpaceToView(_contentLabel, 10)
    .heightIs(20)
    .widthIs(35);
    
    UIView * lineView = [[UIView alloc] init];
    lineView.backgroundColor = LSLineGrayColor;
    [self.contentView addSubview:lineView];
    lineView.sd_layout
    .leftSpaceToView(_lookBtn, 2)
    .topEqualToView(_lookBtn)
    .widthIs(1)
    .heightIs(20);
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.text = @"2天前发布";
    _timeLabel.font = LSFontSize10;
    _timeLabel.textColor = LSTitleGrayColor2;
    [self.contentView addSubview:_timeLabel];
    _timeLabel.sd_layout
    .leftSpaceToView(lineView, 5)
    .centerYEqualToView(lineView)
    .autoHeightRatio(0);
    [_timeLabel setSingleLineAutoResizeWithMaxWidth:180];
    
    _attentBtn = [[UIButton alloc] init];
    [_attentBtn setImage:[UIImage imageNamed:@"attend"] forState:UIControlStateSelected];
    [_attentBtn setImage:[UIImage imageNamed:@"attendNo"] forState:UIControlStateNormal];
    [_attentBtn setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [_attentBtn setTitle:@"0" forState:UIControlStateNormal];
    _attentBtn.titleLabel.font = LSFontSize11;
    [_attentBtn addTarget:self action:@selector(attentBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:_attentBtn];
    
    _attentBtn.sd_layout
    .rightSpaceToView(self.contentView, 0)
    .centerYEqualToView(_timeLabel)
    .widthIs(50)
    .heightIs(20);
    
    _mosaicImageView = [[UIImageView alloc] init];

    [self.contentView addSubview:_mosaicImageView];
    _mosaicImageView.sd_layout
    .leftEqualToView(_iconImageView)
    .rightEqualToView(_shootingLab)
    .topEqualToView(_contentLabel)
    .bottomEqualToView(_contentLabel);
    
    UIView * bottomView = [[UIView alloc] init];
    bottomView.backgroundColor = LSLineGrayColor;
    [self.contentView addSubview:bottomView];
    bottomView.sd_layout
    .leftEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .bottomEqualToView(self.contentView)
    .heightIs(1);
    
}

- (void)setModel:(LSRecommendModel *)model{
    _model = model;
    [_iconImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
//        image = [CommonClass clipImage:image scaleToSize:CGSizeMake(50, 50)];
    }];
    
    _contentLabel.text = model.Title;
    _nickNameLab.text = model.UserDisName;
    _leftShootingLab.text = [NSString stringWithFormat:@"%@命中率",model.RightRate];
    _shootingNumbLabel.text = model.RecentResult;
    _shootingLab.text = [NSString stringWithFormat:@"%@\n命中率",model.RightRate];
    _timeLabel.text = [self splitTheString:model.CreateTime];
    [_attentBtn setTitle:model.ThumbupCount forState:UIControlStateNormal];
    
    
}
- (NSString *)splitTheString:(NSString *)string{
    
    NSMutableArray * array = [string componentsSeparatedByString:@"T"].mutableCopy;
    
    NSMutableArray * leftArray = [array.firstObject componentsSeparatedByString:@"-"].mutableCopy;
    NSMutableArray * rightArray = [array.lastObject componentsSeparatedByString:@":"].mutableCopy;
    [leftArray removeObjectAtIndex:0];
    [rightArray removeLastObject];
    return [NSString stringWithFormat:@"%@ %@",[leftArray componentsJoinedByString:@"-"],[rightArray componentsJoinedByString:@":"]];
}
- (void)lookBtnClicked:(UIButton *)sender{
    
    
}

- (void)attentBtnClicked:(UIButton *)sender{
    if (self.block) {
        self.block(sender);
    }
    
}
@end

#pragma mark -- LSLiveCircleCell
@interface LSLiveCircleCell()

@property (nonatomic, strong) UIImageView * iconImageView;
@property (nonatomic, strong) UILabel * nickNameLab;
//@property (nonatomic, strong) UILabel * professionalLab;
@property (nonatomic, strong) UILabel * timeLab;
@property (nonatomic, strong) UIButton * attentBtn;
@property (nonatomic, strong) UILabel * contentLab;

@end

@implementation LSLiveCircleCell

+ (LSLiveCircleCell *)liveCircleCellByTableView:(UITableView *)tableView{
    LSLiveCircleCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSLiveCircleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    return self;
}
- (void)addContentView{
    _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo1"]];
    [self.contentView addSubview:_iconImageView];
    _iconImageView.sd_layout
    .leftSpaceToView(self.contentView, 10)
    .topSpaceToView(self.contentView, 5);
    
    _nickNameLab = [[UILabel alloc] init];
    _nickNameLab.text = @"精华水月";
    _nickNameLab.font = LSFontSize13;
    _nickNameLab.textColor = LSTitleGrayColor1;
    [self.contentView addSubview:_nickNameLab];
    _nickNameLab.sd_layout
    .leftSpaceToView(_iconImageView, 5)
    .topSpaceToView(self.contentView, 8)
    .autoHeightRatio(0);
    [_nickNameLab setSingleLineAutoResizeWithMaxWidth:180];
    
//    _professionalLab = [[UILabel alloc] init];
//    _professionalLab.text = @"竞猜分析师";
//    _professionalLab.textColor = LSTitleGrayColor2;
//    _professionalLab.font = LSFontSize11;
//
//    [self.contentView addSubview:_professionalLab];
//    _professionalLab.sd_layout
//    .leftEqualToView(_nickNameLab)
//    .topSpaceToView(_nickNameLab, 3)
//    .autoHeightRatio(0);
//    [_professionalLab setSingleLineAutoResizeWithMaxWidth:180];
    
    _contentLab = [[UILabel alloc] init];
    _contentLab.font = LSFontSize12;
    _contentLab.numberOfLines = 0;
    _contentLab.textColor = LSTitleGrayColor1;
    [self.contentView addSubview:_contentLab];
    _contentLab.sd_layout
    .leftEqualToView(_iconImageView)
    .rightSpaceToView(self.contentView, 10)
    .topSpaceToView(_iconImageView, 10)
    .autoHeightRatio(0);
    
    _timeLab = [[UILabel alloc] init];
    _timeLab.text = @"2天前发布";
    _timeLab.font = LSFontSize10;
    _timeLab.textColor = LSTitleGrayColor2;
    [self.contentView addSubview:_timeLab];
    _timeLab.sd_layout
    .leftEqualToView(_iconImageView)
    .topSpaceToView(_contentLab, 10)
    .autoHeightRatio(0);
    [_timeLab setSingleLineAutoResizeWithMaxWidth:180];
    
    _attentBtn = [[UIButton alloc] init];
    [_attentBtn setImage:[UIImage imageNamed:@"attend"] forState:UIControlStateSelected];
    [_attentBtn setImage:[UIImage imageNamed:@"attendNo"] forState:UIControlStateNormal];
    [_attentBtn setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [_attentBtn setTitle:@"0" forState:UIControlStateNormal];
    _attentBtn.titleLabel.font = LSFontSize11;
    [_attentBtn addTarget:self action:@selector(circleAttentBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:_attentBtn];
    
    _attentBtn.sd_layout
    .rightSpaceToView(self.contentView, 0)
    .centerYEqualToView(_timeLab)
    .widthIs(60)
    .heightIs(20);
    
    UIView * bottomView = [[UIView alloc] init];
    bottomView.backgroundColor = LSLineGrayColor;
    [self.contentView addSubview:bottomView];
    bottomView.sd_layout
    .leftEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .bottomEqualToView(self.contentView)
    .heightIs(1);
}

- (void)setModel:(LSTopicModel *)model{
    _model = model;
    _nickNameLab.text = model.UserDisName;
    [_iconImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];
//    [_iconImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
//        
//    }];
    
    _contentLab.text = model.TopicContent;
    _timeLab.text = [self splitTheString:model.CreateTime];
    [_attentBtn setTitle:model.ThumbupCount forState:UIControlStateNormal];
    
}
- (NSString *)splitTheString:(NSString *)string{
    
    NSMutableArray * array = [string componentsSeparatedByString:@"T"].mutableCopy;
    
    NSMutableArray * leftArray = [array.firstObject componentsSeparatedByString:@"-"].mutableCopy;
    NSMutableArray * rightArray = [array.lastObject componentsSeparatedByString:@":"].mutableCopy;
    [leftArray removeObjectAtIndex:0];
    [rightArray removeLastObject];
    return [NSString stringWithFormat:@"%@ %@",[leftArray componentsJoinedByString:@"-"],[rightArray componentsJoinedByString:@":"]];
}


- (void)circleAttentBtnClicked:(UIButton *)sender{
    
    
    
}
@end

